<template>
	<div class="login">
		<!-- 顶部 -->
		<van-nav-bar
			title="注册"
			left-text="返回"
			left-arrow
			@click-left="onClickLeft"
		/>
		
		<!-- 表单 -->
		<van-form @submit="onSubmit">
			<van-field
				v-model="oldPassword"
				type="password"
				name="oldPassword"
				label="旧密码"
				placeholder="密码"
				:rules="[{ required: true, message: '请填写密码' }]"
			/>
      <van-field
				v-model="password"
				type="password"
				name="password"
				label="新密码"
				placeholder="密码"
				:rules="[{ required: true, message: '请填写密码' }]"
			/>

			<div style="margin: 16px">
				<van-button round block type="info" native-type="submit"
					>确认修改</van-button
				>
			</div>
		</van-form>
	</div>
</template>

<script>
import { Toast } from "vant";
// import { registerAPL } from "../services/anth";
// import { setToken } from "../utils/tools";
import { update_pwdAPL } from "../services/anth";

export default {
	data() {
		return {
			password: "",
			oldPassword: "",

			fileList: [],
		};
	},
	methods: {
		//退回
		onClickLeft() {
			this.$router.go(-1);
		},
		//修改密码
		async onSubmit(values) {
			const res = await update_pwdAPL(values);
      // console.log(res);
      console.log(values);
			if (res.code == 1) {
				Toast.success({
					message: "修改成功",
				});
				//修改后跳转
				this.$router.replace({
					name: "User",
				});
			} else {
				Toast.fail({
					message: res.msg,
				});
			}
		},
	},
};
</script>

<style lang="scss">
.van-uploader__wrapper {
	margin-top: 20px;
	margin-left: 40vw;
}
</style>
